package com.monster.security.handler;

import com.monster.security.utils.SecurityUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 权限不足的处理逻辑
 *
 * @author kuangxz
 * @version 1.0
 * @date 2021/2/5 17:38
 */
@Component
public class MonsterAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        SecurityUtils.writerResponseData(response, String.valueOf(HttpServletResponse.SC_FORBIDDEN),null, "权限不足!", false);
    }
}
